package com.cloud.wyf.Service.imp;

import com.cloud.wyf.Entity.*;
import com.cloud.wyf.Entity.Dto.LeaderShipDto;
import com.cloud.wyf.Entity.Dto.MiddelDto;
import com.cloud.wyf.Mapper.*;
import com.cloud.wyf.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImp implements UserService {
    @Autowired
    UserMapper um;
    @Autowired
    MiddelMapper mm;
    @Autowired
    OrdinaryMapper om;
    @Autowired
    LeaderMapper lm;
    @Autowired
    PartMapper pm;
    @Autowired
    LeaderShipMapper leaderShipMapper;

    @Override
    public int updateInfo(List<Middel> list) {
        return mm.updateInfo(list);
    }

    @Override
    public List<Leader> selectAll() {
        return lm.selectAll();
    }

    @Override
    public User selectByName(String nickname) {
        return um.selectByName(nickname);
    }

    @Override
    public int MultiAddMi(List<Middel> list) {
        return mm.MultiAdd(list);
    }

    @Override
    public int MultiAddOr(List<Ordinary> list) {
        return om.MultiAdd(list);
    }

    @Override
    public List<Middel> selectAllMi() {
        return mm.selectAllMi();
    }

    @Override
    public PageBean<MiddelDto> selectByPage(int currentPage, int pageSize){
        int begin=(currentPage-1)*2;
        List<Middel> list = mm.selectPage(begin, pageSize);
        List<MiddelDto> list1=new ArrayList<>();
        int total = mm.selectTotal();
        for(Middel middel:list){
            if(middel.getStatus()==1){
                list1.add(new MiddelDto(middel.getUid(),middel.getRealname(),middel.getPart(),middel.getPosition(),middel.getLevel(),"已上传",middel.getSummarypath(),middel.getSummarytime(),middel.getStatus()));
            }else if(middel.getStatus()==2)list1.add(new MiddelDto(middel.getUid(),middel.getRealname(),middel.getPart(),middel.getPosition(),middel.getLevel(),"待审核",middel.getSummarypath(),middel.getSummarytime(),middel.getStatus()));
            else if(middel.getStatus()==3)list1.add(new MiddelDto(middel.getUid(),middel.getRealname(),middel.getPart(),middel.getPosition(),middel.getLevel(),"审核不通过",middel.getSummarypath(),middel.getSummarytime(),middel.getStatus()));
            else list1.add(new MiddelDto(middel.getUid(),middel.getRealname(),middel.getPart(),middel.getPosition(),middel.getLevel(),"未上传",middel.getSummarypath(),middel.getSummarytime(),middel.getStatus()));
        }
        PageBean<MiddelDto> pageBean=new PageBean<MiddelDto>(total,list1);
        return pageBean;
    }

    @Override
    public PageBean<LeaderShipDto> selectByPageL(int currentPage, int pageSize) {
        int begin=(currentPage-1)*2;
        List<LeaderShip> list = leaderShipMapper.selectPageL(begin, pageSize);
        List<LeaderShipDto> list1=new ArrayList<>();
        int total = leaderShipMapper.selectTotalL();
        for(LeaderShip middel:list){
            if(middel.getStatus()==1){
                list1.add(new LeaderShipDto(middel.getPart(),"已上传",middel.getReportpath(),middel.getReporttime(),middel.getUid(),middel.getStatus()));
            }else if(middel.getStatus()==2)list1.add(new LeaderShipDto(middel.getPart(),"待审核",middel.getReportpath(),middel.getReporttime(),middel.getUid(),middel.getStatus()));
            else if(middel.getStatus()==3)list1.add(new LeaderShipDto(middel.getPart(),"审核不通过",middel.getReportpath(),middel.getReporttime(),middel.getUid(),middel.getStatus()));
            else list1.add(new LeaderShipDto(middel.getPart(),"未上传",middel.getReportpath(),middel.getReporttime(),middel.getUid(),middel.getStatus()));
        }
        PageBean<LeaderShipDto> pageBean=new PageBean<LeaderShipDto>(total,list1);
        return pageBean;
    }

    @Override
    public int updateLeaderShipStatus(int status, String part) {
        return leaderShipMapper.updateStatus(status,part);
    }

    @Override
    public int uploadS(String path, String uid,int status) {
        return mm.updateS(uid,path,status);
    }

    @Override
    public List<Leader> selectLeaderByUids(List<String> uids) {
        return lm.selectLeaderByUids(uids);
    }

    @Override
    public List<LeaderShip> selectAllLeaderShip() {
        return leaderShipMapper.selectAllLeaderShip();
    }

    @Override
    public Leader selectLeaderById(String id) {
        return lm.selectById(id);
    }

    @Override
    public Ordinary selectOrdinaryById(String id) {
        return om.selectById(id);
    }

    @Override
    public Part selectByPart(String part) {
        return pm.selectByPart(part);
    }

    @Override
    public List<Part> selectByDirectPart(String directPart) {
        return pm.selectByDirectPart(directPart);
    }

    @Override
    public Middel selectMidById(String uid) {
        return mm.selectMidById(uid);
    }

    @Override
    public User selectUserById(String id) {
        return um.selectById(id);
    }

    @Override
    public int MultiUser(List<User> list) {
        return um.MultiAdd(list);
    }

    @Override
    public List<Part> selectAllPart() {
        return pm.selectAll();
    }

    @Override
    public List<Ordinary> selectAllOrdinary() {
        return om.selectAllOrdinary();
    }

    @Override
    public List<User> MultiSelect(List<String> list) {
        return um.MultiSelect(list);
    }


    @Override
    public int totalNum() {
        return pm.totalNum();
    }

    @Override
    public int updateStatus(int status, String uid) {
        return mm.updateStatus(status,uid);
    }

    @Override
    public LeaderShip selectLeaderShipByPart(String part) {
        return leaderShipMapper.selectLeaderShipByPart(part);
    }

    @Override
    public int updateLeaderShip(LeaderShip leaderShip) {
        return leaderShipMapper.updateLeaderShip(leaderShip);
    }


    @Override
    public Boolean outport(List<User> list, List<Ordinary> list1) {
        int i = um.MultiAdd(list);
        int i1 = om.MultiAdd(list1);
        if(i>0&&i1>0) return true;
        else return false;
    }

    @Override
    public Boolean startVote(int status,int status2) {
        int i = lm.updateStatus(status);
        int i2 = om.updateStatus(status2);
        if(i>0&&i2>0) return true;
        return false;
    }

    @Override
    public Boolean closeVote(int status,int status2) {
        int i = lm.updateStatus(status);
        int i2 = om.updateStatus(status2);
        if(i>0&&i2>0) return true;
        return false;
    }

}
